<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <body>
        <form method="post" id="login-form">
            用户名：<input type="text" name="username" />
            <input type="button" value="登录" id="login-btn"/>
        </form>
    </body>

    <script src="js/jquery-1.12.3.min.js"></script>
    <script>
        $("#login-btn").click(function () {
            $.ajax({
                url: 'http://localhost:8080/product-sys/api/chat/login.do',
                type: 'post',
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                data: $("#login-form").serialize(),
                dataType: 'json',
                success: function (responseData) {
                    if (responseData.code == 200) {
                        // 把当前登录的帐号保存到会话存储中
                        console.log(responseData.value);
                        sessionStorage.setItem("user", responseData.value);
                        window.location.href = "main.html";
                    } else {
                        alert(responseData.msg);
                    }
                }
            });
        });
    </script>
</body>

</html>